package shellstation;

import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JFrame;

public class MainMenu extends JFrame implements ActionListener  {
    private int user;
    private JFrame frame;

    private JPanel panel;
    private JPanel panel2;

    private JLabel shellLabel;
    private JLabel shellText;
    private JLabel shellText2;
    private JLabel shellText3;

    private JButton userButton;
    private JButton salesButton;
    private JButton inventoryButton;
    private JButton reportButton;
    private JButton logoutButton;

    private Icon userIcon;
    private Icon salesIcon;
    private Icon inventoryIcon;
    private Icon reportIcon;
    private Icon shellIcon;
     private Icon logoutIcon;

    private Color yellow = new Color(255, 218, 63);
    private Color gray = new Color(182, 182, 182);
    private Color red = new Color(226, 0, 0);


    public void MainMenu() {

        userIcon = new ImageIcon(getClass().getResource("image/user.gif"));
        inventoryIcon = new ImageIcon(getClass().getResource("image/inventory.gif"));
        reportIcon = new ImageIcon(getClass().getResource("image/report.gif"));
        salesIcon = new ImageIcon(getClass().getResource("image/sales.gif"));
        logoutIcon = new ImageIcon(getClass().getResource("image/log out.png"));

        shellIcon = new ImageIcon(getClass().getResource("image/shell.gif"));

        shellLabel = new JLabel();
        shellLabel.setIcon(shellIcon);
        shellLabel.setBounds(150, 75, 150, 150);

        shellText = new JLabel("Sta. Elena Shell Staion");
        shellText.setBounds(55, 150, 400, 200 );
        shellText.setFont(new Font("Hobo Std", Font.BOLD, 32));

        shellText2 = new JLabel("Inventory and Sales");
        shellText2.setBounds(88, 175, 350, 200);
        shellText2.setFont(new Font("Hobo Std", Font.BOLD, 32));

        shellText3 = new JLabel("System");
        shellText3.setBounds(170, 200, 300, 200);
        shellText3.setFont(new Font("Hobo Std", Font.BOLD, 32));

        frame = new JFrame("Shell Station - Inventroy Sales System");
        frame.setSize(750, 450);
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setResizable(false);

        userButton = new JButton("User", userIcon);
        userButton.setBackground(gray);
        userButton.setBounds(18, 25,250, 50);
        userButton.setFont(new Font("Arial", Font.BOLD, 20));
        userButton.addActionListener(this);

        salesButton = new JButton("Sales", salesIcon);
        salesButton.setBackground(gray);
        salesButton.setBounds(18, 100, 250, 50);
        salesButton.setFont(new Font("Arial", Font.BOLD, 20));
        salesButton.addActionListener(this);

        inventoryButton = new JButton("Inventory", inventoryIcon);
        inventoryButton.setBackground(gray);
        inventoryButton.setBounds(18, 175, 250, 50);
        inventoryButton.setFont(new Font("Arial", Font.BOLD, 20));
        inventoryButton.addActionListener(this);

        reportButton= new JButton("Report", reportIcon);
        reportButton.setBackground(gray);
        reportButton.setBounds(18, 250, 250, 50);
        reportButton.setFont(new Font("Arial", Font.BOLD, 20));
        reportButton.addActionListener(this);

        logoutButton= new JButton("Logout", logoutIcon);
        logoutButton.setBackground(gray);
        logoutButton.setBounds(18, 325, 250, 50);
        logoutButton.setFont(new Font("Arial", Font.BOLD, 20));
        logoutButton.addActionListener(this);

        panel = new JPanel(null);
        panel.setBackground(red);

        panel2= new JPanel(null);
        panel2.setBounds(300, 0, 750, 424);
        panel2.setBackground(yellow);



        addpanelComponents();
        addpanel2Components();

        panel.add(panel2);
        frame.add(panel);
    }

    public void actionPerformed(ActionEvent e){

     
        if(e.getSource() == userButton && this.user==2){

         JOptionPane.showMessageDialog( null, "Invalid User, You must be an Admin" );
        }
        else if(e.getSource() == reportButton && this.user==2){

         JOptionPane.showMessageDialog( null, "Invalid User, You must be an Admin" );
        }

        else if(e.getSource() == salesButton )
        {
           frame.dispose();

           SalesView s= new SalesView();
           s.SalesView();
           s.getuser(this.user);
        }
         else if(e.getSource() == userButton && this.user==1){

            User1 us = new User1();
             frame.dispose();
             us.User1();
             us.getuser(this.user);
        }    
        else if(e.getSource() == reportButton && this.user==1){

            ReportView r = new ReportView();
            r.ReportView();
            frame.dispose();
            r.getuser(this.user);
        
        }
        else if(e.getSource() == inventoryButton ){

            InventoryView i= new InventoryView();
            i.InventoryView();
            i.getuser(this.user);
            frame.dispose();

        }

         else if(e.getSource() == logoutButton ){

            Main m = new Main();
            JOptionPane.showMessageDialog( null, "Good bye!" );
            frame.dispose();
            m.main();

        }
         
    }

    public void addpanelComponents(){

        panel.add(userButton);
        panel.add(salesButton);
        panel.add(inventoryButton);
        panel.add(reportButton);
        panel.add(logoutButton);

    }

    public void addpanel2Components(){

        panel2.add(shellLabel);
        panel2.add(shellText);
        panel2.add(shellText2);
        panel2.add(shellText3);
    }

    public void getuser(int i){
        this.user = i;
        
    }
}

